# coding=utf-8
# https://leetcode.cn/problems/squares-of-a-sorted-array/
from typing import List


class Solution:
    def sortedSquares(self, nums: List[int]) -> List[int]:
        ls = []
        l = 0
        r = len(nums) - 1
        while r >= l:
            if nums[r] ** 2 > nums[l] ** 2:
                ls.insert(0, nums[r] ** 2)
                r -= 1
            else:
                ls.insert(0, nums[l] ** 2)
                l += 1
        return ls


s = Solution()
print(s.sortedSquares([-4, -1, 0, 3, 10]))
